<?php

namespace App\Http\Controllers\Backend;

use App\DataTables\WechatUserSessionDataTable;
use App\Http\Requests;
use App\Http\Requests\CreateWechatUserSessionRequest;
use App\Http\Requests\UpdateWechatUserSessionRequest;
use App\Repositories\WechatUserSessionRepository;
use Flash;
use App\Http\Controllers\AppBaseController;
use Response;

class WechatUserSessionController extends AppBaseController
{
    /** @var  WechatUserSessionRepository */
    private $wechatUserSessionRepository;

    public function __construct(WechatUserSessionRepository $wechatUserSessionRepo)
    {
        $this->wechatUserSessionRepository = $wechatUserSessionRepo;
    }

    /**
     * Display a listing of the WechatUserSession.
     *
     * @param WechatUserSessionDataTable $wechatUserSessionDataTable
     * @return Response
     */
    public function index(WechatUserSessionDataTable $wechatUserSessionDataTable)
    {
        return $wechatUserSessionDataTable->render('backend.wechat_user_sessions.index');
    }

    /**
     * Show the form for creating a new WechatUserSession.
     *
     * @return Response
     */
    public function create()
    {
        return view('backend.wechat_user_sessions.create');
    }

    /**
     * Store a newly created WechatUserSession in storage.
     *
     * @param CreateWechatUserSessionRequest $request
     *
     * @return Response
     */
    public function store(CreateWechatUserSessionRequest $request)
    {
        $input = $request->all();

        $wechatUserSession = $this->wechatUserSessionRepository->create($input);

        Flash::success(trans('flash.controller.save_success', ['model' => 'Wechat User Session']));

        return redirect(route('wechatUserSessions.index'));
    }

    /**
     * Display the specified WechatUserSession.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $wechatUserSession = $this->wechatUserSessionRepository->findWithoutFail($id);

        if (empty($wechatUserSession)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Wechat User Session']));

            return redirect(route('wechatUserSessions.index'));
        }

        return view('backend.wechat_user_sessions.show')->with('wechatUserSession', $wechatUserSession);
    }

    /**
     * Show the form for editing the specified WechatUserSession.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $wechatUserSession = $this->wechatUserSessionRepository->findWithoutFail($id);

        if (empty($wechatUserSession)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Wechat User Session']));

            return redirect(route('wechatUserSessions.index'));
        }

        return view('backend.wechat_user_sessions.edit')->with('wechatUserSession', $wechatUserSession);
    }

    /**
     * Update the specified WechatUserSession in storage.
     *
     * @param  int              $id
     * @param UpdateWechatUserSessionRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateWechatUserSessionRequest $request)
    {
        $wechatUserSession = $this->wechatUserSessionRepository->findWithoutFail($id);

        if (empty($wechatUserSession)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Wechat User Session']));

            return redirect(route('wechatUserSessions.index'));
        }

        $wechatUserSession = $this->wechatUserSessionRepository->update($request->all(), $id);

        Flash::success(trans('flash.controller.update_success', ['model' => 'Wechat User Session']));

        return redirect(route('wechatUserSessions.index'));
    }

    /**
     * Remove the specified WechatUserSession from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $wechatUserSession = $this->wechatUserSessionRepository->findWithoutFail($id);

        if (empty($wechatUserSession)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Wechat User Session']));

            return redirect(route('wechatUserSessions.index'));
        }

        $this->wechatUserSessionRepository->delete($id);

        Flash::success(trans('flash.controller.delete_success', ['model' => 'Wechat User Session']));

        return redirect(route('wechatUserSessions.index'));
    }
}
